package com.leoman.spinningmachine.tab3;

import android.content.Intent;
import android.util.Log;
import android.view.View;
import android.widget.TextView;

import com.facebook.drawee.view.SimpleDraweeView;
import com.leoman.helper.util.FrescoUtil;
import com.leoman.spinningmachine.R;
import com.leoman.spinningmachine.base.BaseFragment;
import com.leoman.spinningmachine.constant.Constant;
import com.leoman.spinningmachine.http.APIResponse;
import com.leoman.spinningmachine.util.DialogUtils;
import com.leoman.spinningmachine.util.SharedPreferencesUtils;

import butterknife.BindView;
import butterknife.OnClick;

import static com.leoman.spinningmachine.constant.Urls.HEAD_IMAGE;

/**
 * 我的
 */
public class UserFragment extends BaseFragment {

    @BindView(R.id.iv_pic)
    SimpleDraweeView ivPic;
    @BindView(R.id.tv_name)
    TextView tvName;
    @BindView(R.id.tv_tag)
    TextView tvTag;

    @Override
    protected int getContentViewLayoutID() {
        return R.layout.fg_user;
    }

    @Override
    protected void initView(View view) {
        tvTag.setText("" + SharedPreferencesUtils.getInstance().getString(Constant.DEPYNAME));
        tvName.setText("" + SharedPreferencesUtils.getInstance().getString(Constant.NICKNAME));

        Log.e("----进入个人中心----", "执行");
        Log.e("----个人中心头像----", SharedPreferencesUtils.getInstance().getString(Constant.HEADPATH));
        FrescoUtil.setImg(getActivity(), ivPic, HEAD_IMAGE + SharedPreferencesUtils.getInstance().getString(Constant.HEADPATH));
    }

    @Override
    protected void initData() {
    }

    @OnClick({R.id.tv_1, R.id.rl_2, R.id.rl_3, R.id.rl_4, R.id.tv_5, R.id.tv_6})
    void click(View view) {
        switch (view.getId()) {
            case R.id.tv_1://设置
                getActivity().startActivity(new Intent(getActivity(), UserSettingActivity.class));
                break;
            case R.id.rl_2://打卡
                getActivity().startActivity(new Intent(getActivity(), CardRecordActivity.class));
                break;
            case R.id.rl_3://请假
                getActivity().startActivity(new Intent(getActivity(), LeaveActivity.class));
                break;
            case R.id.rl_4://权限
                getActivity().startActivity(new Intent(getActivity(), MyPermissionActivity.class));
                break;
            case R.id.tv_5://密码修改
                getActivity().startActivity(new Intent(getActivity(), UpPwdActivity.class));
                break;
            case R.id.tv_6://授权开门
                getActivity().startActivity(new Intent(getActivity(), InvitationActivity.class));
                break;
        }
    }


    @Override
    public void onResume() {
        super.onResume();
        tvName.setText("" + SharedPreferencesUtils.getInstance().getString(Constant.NICKNAME));
        FrescoUtil.setImg(getActivity(), ivPic, HEAD_IMAGE + SharedPreferencesUtils.getInstance().getString(Constant.HEADPATH));
    }

    @Override
    public void OnSuccessData(APIResponse apiResponse, Integer tag) {
        super.OnSuccessData(apiResponse, tag);
        DialogUtils.getInstance().cancel();
        if (tag == 1) {
//            Intent intent = new Intent(getActivity(), WebActivity.class);
//            intent.putExtra("url",url);
//            startActivity(intent);
        }
    }
}
